use std::path::Path;
use rusqlite;
pub fn converter(input: &str) -> String {
    let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let db_path = Path::new(&dir).join("WG.db");
    let conn = rusqlite::Connection::open(db_path).unwrap();
    let mut stmt = conn.prepare("SELECT wg FROM wg WHERE word = ?1").unwrap();
    let mut wg_iter = stmt.query_map([input], |row| row.get(0)).unwrap();
    wg_iter.next().unwrap().unwrap()
}
// mod tests {
//     #[test]
//     fn new_db() {
//         let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
//         let db_path = std::path::Path::new(&dir).join("WG.db");
//         let conn = rusqlite::Connection::open(db_path).unwrap();
//         conn.execute("CREATE TABLE wg (word TEXT PRIMARY KEY, wg TEXT)", []).unwrap();
//     }
//     #[test]
//     fn add_db(){
//         let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
//         let db_path = std::path::Path::new(&dir).join("WG.db");
//         let conn = rusqlite::Connection::open(db_path).unwrap();
//         let test_cases = [
//             ("中国", "Chung kuo"),
//             ("@", ""),
//             ("诸葛亮", "Chu ko liang"),
//             ("孙中山", "Sun chung shan"),
//             ("台湾", "T'ai wan"),
//             ("香港", "Hsiang kang"),
//             ("澳門", "Ao men"),
//             ("川普", "Ch'uan p'u"),
//             ("四川", "Ssu ch'uan"),
//             ("廣州", "Kuang chou"),
//         ];
//         for i in test_cases {
//             conn.execute("INSERT INTO wg (word, wg) VALUES (?1, ?2)", [i.0, i.1]).unwrap();
//         }
//     }
// }